package cn.fay.chapter10;

import java.util.Random;

public class Test17 {

	public static void gambling(GamblingFactory factory){
		Gambling gambling=factory.getGambling();
		gambling.toss();
	}
	public static void main(String[] args) {
		gambling(Coin.factory);
		System.out.println("-------------------");
		gambling(Dice.factory);
	}

}
interface Gambling{
	void toss();
}
interface GamblingFactory{
	Gambling getGambling();
}

class Coin implements Gambling{
	private Coin(){}
	@Override
	public void toss() {
		Random random=new Random();
		int i=random.nextInt(2);
		if (i==0)
			System.out.println("I toss a coin, it show the head.");
		else
			System.out.println("I toss a coin, it show the flower.");
	}
	public static GamblingFactory factory=new GamblingFactory() {
		@Override
		public Gambling getGambling() {
			return new Coin();
		}
	};
}
class Dice implements Gambling{
	private Dice(){}
	@Override
	public void toss() {
		Random random=new Random();
		int i= random.nextInt(6)+1;
		System.out.println("I throw the dice,it show "+i+" points.");
	}
	public static GamblingFactory factory=new GamblingFactory() {
		@Override
		public Gambling getGambling() {
			return new Dice();
		}
	};
}
